package net.mihome.app.adapter;

import android.content.Context;
import android.graphics.BitmapFactory;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.nostra13.universalimageloader.core.ImageLoader;

import net.mihome.app.R;
import net.mihome.app.bean.RepairRequire;
import net.mihome.app.bean.Shop;
import net.mihome.app.common.BitmapManager;

import java.util.ArrayList;
import java.util.List;

public class ListViewBaoxiuAdapter extends ArrayAdapter<RepairRequire> {

    private static final String TAG = "SampleAdapter";
    private LayoutInflater listContainer;
    private List<RepairRequire> listItems=new ArrayList<RepairRequire>();
    private BitmapManager bmpManager;
    private Context context;

    public ListViewBaoxiuAdapter(Context context, int resource, List<RepairRequire> objects) {
        super(context, resource, objects);
        listContainer = LayoutInflater.from(context);
        listItems=objects;
        bmpManager=new BitmapManager(BitmapFactory.decodeResource(context.getResources(), R.drawable.tweet_confirm_dialog_load));
        // TODO Auto-generated constructor stub
    }
    public ListViewBaoxiuAdapter(final Context context, final int textViewResourceId) {
        super(context, textViewResourceId);
        listContainer = LayoutInflater.from(context);
    }

    @Override
    public View getView(final int position, View v, final ViewGroup parent) {
        if(v==null){
            v = listContainer.inflate(R.layout.mifuwu_baoxiu_listview_item, parent, false);
        }
        if(listItems==null||listItems.get(position)==null){
            return v;
        }
        ImageView ivImageView=(ImageView) v.findViewById(R.id.baoxiu_img);
        RepairRequire repairRequire=listItems.get(position);
        String images=repairRequire.getImgs();
        if(images!=null&&!"".equals(images)){
            String firstImg=images.split(";")[0];
            ImageLoader.getInstance().displayImage(firstImg,ivImageView);
        }else{
            ivImageView.setImageResource(R.drawable.icon);
        }
        TextView content= (TextView) v.findViewById(R.id.baoxiu_content);
        content.setText(repairRequire.getContent());
        TextView mark= (TextView) v.findViewById(R.id.baoxiu_mark);
        mark.setText(repairRequire.getMark());
        TextView statusName= (TextView) v.findViewById(R.id.baoxiu_status_name);
        statusName.setText(repairRequire.getStatus_name());
        TextView createAt= (TextView) v.findViewById(R.id.baoxiu_create_at);
        createAt.setText(repairRequire.getCreate_at());
        return v;
    }
    @Override
    public int getCount() {
        // TODO Auto-generated method stub
        return listItems.size();
    }
    @Override
    public RepairRequire getItem(int position) {
        // TODO Auto-generated method stub
        return listItems.get(position);
    }
    @Override
    public long getItemId(int position) {
        // TODO Auto-generated method stub
        return listItems.get(position).getId();
    }

}
